package com.zzg.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.zzg.base.response.BaseResponse;
import com.zzg.base.response.PageResponse;
import com.zzg.quartz.condition.SysJobLogCondition;
import com.zzg.quartz.domain.SysJobLog;
import com.zzg.quartz.service.ISysJobLogService;
import com.zzg.util.result.ResultUtil;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

@Api(value = "定时任务日志记录", description = "定时任务日志记录监控管理")
@Controller
@RequestMapping("/jobLog")
@Slf4j
public class SysJobLogController {
	private String prefix = "admin/job";

    private final ISysJobLogService jobLogService;

    private static final String JOB_LOG = "jobLog";

    @Autowired
    public SysJobLogController(ISysJobLogService jobLogService) {
        this.jobLogService = jobLogService;
    }

    @GetMapping()
    public String jobLog() {
        return prefix + "/jobLog";
    }

    @PostMapping("/list")
    @ResponseBody
    public PageResponse list(SysJobLogCondition jobLog) {
        PageInfo<SysJobLog> list = jobLogService.selectJobLogList(jobLog);
        return ResultUtil.tablePage(list);
    }


  /** 导出功能暂停开放
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysJobLog jobLog) {
        List<SysJobLog> list = jobLogService.selectJobLogList(jobLog);
        ExcelUtil<SysJobLog> util = new ExcelUtil<>(SysJobLog.class);
        return util.exportExcel(list, "调度日志");
    } **/

  
    @PostMapping("/remove")
    @ResponseBody
    public BaseResponse remove(String ids) {
    	int row = jobLogService.deleteJobLogByIds(ids);
        return row > 0 ? ResultUtil.success("任务日志清理成功") : ResultUtil.error("任务日志清理识别");
    }

  
    @GetMapping("/detail/{jobLogId}")
    public String detail(@PathVariable("jobLogId") Long jobLogId, ModelMap mmap) {
        mmap.put("name", JOB_LOG);
        mmap.put(JOB_LOG, jobLogService.selectJobLogById(jobLogId));
        return prefix + "/detail";
    }

  
    @PostMapping("/clean")
    @ResponseBody
    public BaseResponse clean() {
        jobLogService.cleanJobLog();
        return ResultUtil.success("任务日志清理成功");
    }
}
